package com.company.linkedList;

import com.company.base.BaseNode;

public class ListNode extends BaseNode {
    public ListNode next;

    public static ListNode buildSampleList(){
        return buildSampleList(5);
    }

    public static ListNode buildSampleList(int size){
        ListNode head= new ListNode(0);
        ListNode node = head;
        for (int i = 1; i < size; i++) {
            node.next = new ListNode(i);
            node = node.next;
        }
        printLinkedList(head);
        return head;
    }
    public ListNode(Integer value) {
        super(value);
    }


    public static void  printLinkedList(ListNode head){
        ListNode node = head;
        StringBuilder stringBuilder=new StringBuilder();
        while (node!=null){
            stringBuilder.append(node.printValue());
            stringBuilder.append("-->");
            node = node.next;
        }
        stringBuilder.append("null");
        System.out.println(stringBuilder.toString());
    }
}
